package com.example.hissys.controller;

import com.example.hissys.entity.DoctorSchedule;
import com.example.hissys.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import java.util.List;

@RestController
@RequestMapping("/api/schedules")
@CrossOrigin(origins = "*")
@Slf4j
public class ScheduleController {
    @Autowired
    private ScheduleService scheduleService;

    /**
     * 获取医生排班信息
     * @param doctorId 医生ID
     * @return 排班列表
     */
    @GetMapping("/doctor/{doctorId}")
    public ResponseEntity<?> getDoctorSchedule(@PathVariable Integer doctorId) {
        try {
            List<DoctorSchedule> schedules = scheduleService.getDoctorSchedule(doctorId);
            if (schedules.isEmpty()) {
                return ResponseEntity.notFound().build();
            }
            return ResponseEntity.ok(schedules);
        } catch (Exception e) {
            log.error("Error fetching schedule for doctor ID: {}", doctorId, e);
            return ResponseEntity.badRequest().body("获取排班信息失败：" + e.getMessage());
        }
    }
} 